package com.zztpc.easybuy.dao;

import com.zztpc.easybuy.db.IDB;
import com.zztpc.easybuy.db.MysqlDB;
import com.zztpc.easybuy.vo.User;
import com.zztpc.easybuy.vo.vo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;


public class UserDao implements IDAO{
    @Override





    public boolean insert(vo vo) throws SQLException {
        IDB db=new MysqlDB();
        Connection conn=db.getConnection();
        PreparedStatement ps=conn.prepareStatement("insert into t_easybuy_user(eu_user_id,eu_user_name,eu_password)value (?,?,?)");
        User user=(User)vo;
        ps.setString(1,user.getEu_user_id());
        ps.setString(2,user.getEu_user_name());
        ps.setString(3,user.getEu_password());
        int i=ps.executeUpdate();
        ps.close();
        db.closeConn();
        return i>0;
    }

    @Override
    public List getAll() throws SQLException {
        return null;
    }

    @Override
    public boolean deleteByID(vo vo) throws SQLException {
        return false;
    }

    @Override
    public boolean update(vo vo) throws SQLException {
        return false;
    }

    @Override
    public vo getByID(vo vo) throws SQLException {
        return null;
    }

    public static void main(String[] args) {
        UserDao u=new UserDao();
        User user=new User();
        user.setEu_user_id("003");
        user.setEu_user_name("caa");
        user.setEu_password("333");
        try {
            if(u.insert(user)){
                System.out.println("succ");
            }else{
                System.out.println("error");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
